#include <iostream>

#include <vector>

using namespace std;

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int re = 0;
        vector<int> copy = prices;

        for (int i = 0; i < prices.size(); i++) {
            for (int j = i + 1; j < prices.size(); j++) {
                re = std::max(re, copy[j] - prices[i]);
            }
        }
        return re;
    }
};

bool test01() {
    Solution solution;
    vector<int> input = {7, 1, 5, 3, 6, 4};
    int result = solution.maxProfit(input);
    int expected = 5;
    std::cout << "输出：" << result << std::endl;
    std::cout << "预期结果：" << expected << std::endl;
    bool pass = (result == expected);
    std::cout << "测试" << (pass ? "通过" : "失败") << std::endl;
    return pass;
}

bool test02() {
    Solution solution;
    vector<int> input = {7, 6, 4, 3, 1};
    int result = solution.maxProfit(input);
    int expected = 0;
    std::cout << "输出：" << result << std::endl;
    std::cout << "预期结果：" << expected << std::endl;
    bool pass = (result == expected);
    std::cout << "测试" << (pass ? "通过" : "失败") << std::endl;
    return pass;
}

int main() {
    std::cout << "this is Leetcode-70-demo." << std::endl;
    std::cout << "test01:" << std::endl;
    int total = 0, passed = 0;
    total++; if (test01()) passed++;

    std::cout << "test02:" << std::endl;
    total++; if (test02()) passed++;

    std::cout << "\n通过用例：" << passed << "/" << total
              << "，通过率：" << (total ? (passed * 100 / total) : 0) << "%" << std::endl;
    return 0;
}
